package com.example.livedatatest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.example.livedatatest.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private ViewModelWithLiveData viewModelWithLiveData;
    private ActivityMainBinding bing;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bing = DataBindingUtil.setContentView(this,R.layout.activity_main);
        viewModelWithLiveData = new ViewModelProvider(this).get(ViewModelWithLiveData.class);
        bing.setData(viewModelWithLiveData);
//        数据变化的观察
        bing.setLifecycleOwner(this);

    }
}